package com.ocom.payconfig.controller;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.ocom.common.AcpService;
import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.card.*;
import com.ocom.common.entity.pay.EntityXfRecordProcessExtend;
import com.ocom.common.entity.payconfig.EntityReceiptAddress;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.GetMealDetailListBRequest;
import com.ocom.common.request.payconfig.KitchenPrinter.*;
import com.ocom.common.request.payconfig.KitchenPrinter.dto.KitchenPrtListDto;
import com.ocom.common.request.payconfig.adreceiptinfo.GetAdReceiptInfoRequest;
import com.ocom.common.request.payhandle.GetRecordByOrderNoRequest;
import com.ocom.common.request.web.GetPointMealSendReportsRequest;
import com.ocom.common.request.web.GetPointMealSendReportsXMRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.*;
import com.ocom.common.utils.feie.Order;
import com.ocom.common.utils.feie.PrintUtil4;
import com.ocom.common.vo.payconfig.MealDetailBVo;
import com.ocom.common.vo.payconfig.kitchenprinter.GetSchemeOnPrtInfoDto;
import com.ocom.common.vo.payconfig.kitchenprinter.GoodsListProcessDishesDto;
import com.ocom.common.vo.payconfig.kitchenprinter.PlanKitchenPrinterRequest;
import com.ocom.common.vo.payconfig.kitchenprinter.PointConfigOnPointInfoDto;
import com.ocom.common.vo.xfrecode.GetPointMealSendVo;
import com.ocom.payconfig.client.PayhandleClientService;
import com.ocom.payconfig.client.XfRecordFeign;
import com.ocom.payconfig.service.*;
import com.ocom.redis.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@RestController
@Slf4j
public class KitchenPrtInfoController {

    @Autowired
    private KitchenPrtInfoService kitchenPrtInfoService;
    @Autowired
    private KitchenPrtSchemeService kitchenPrtSchemeService;
    @Autowired
    private KitchenPrtRecordService kitchenPrtRecordService;
    @Autowired
    private PointConfigService pointConfigService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private PayhandleClientService payhandleClientService;
    @Autowired
    private ReceiptAddressService receiptAddressService;

    @Autowired
    private XfMealTimeService xfMealTimeService;

    @Autowired
    private XfMealInfoService mealInfoService;

    @Autowired
    private XfRecordFeign xfRecordFeign;

    @Autowired
    private XfRecordProcessExtendService xfRecordProcessExtendService;

    @Autowired
    private XfMealTimeService mealTimeService;


    private static final String URL = "http://api.feieyun.cn/Api/Open/";
    private static final String USER = "junshu@qq.com";
    private static final String U_KEY = "eKJBgRnzRLTDuWRw";

    @PostMapping(PayConfigUrl.Url_kitchenPrtList)
    public Result kitchenPrtList(@RequestBody KitchenPrinterOnShowRequest request) {

        List<KitchenPrtListDto> list = kitchenPrtInfoService.kitchenPrtList(request.getComId(), request.getRestId(), request.getPrtId(), request.getPage(), request.getSize());
        PageInfo<KitchenPrtListDto> pageInfo = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put("total", pageInfo.getTotal());
        map.put("list", list);
        return ResultUtil.success(map);
    }

    @PostMapping(PayConfigUrl.Url_feieNewPtr)
    public Result feieNewPtr(@RequestBody KitchenPrinterAddRequest request) {
        JSONObject add = printerAddlist(request.getPrtSn(), request.getPrtKey(), request.getPrtName(), request.getPrtPhone());
        if (200 != add.getInteger("code")) {
            return ResultUtil.error(ResultEnum.Err_4002, add);
        }

        JSONObject info = printerInfo(request.getPrtSn());
        if (!"ok".equals(info.getString("msg"))) {
            return ResultUtil.error(ResultEnum.Err_4002, add);
        }
        JSONObject printerInfoData = info.getJSONObject("data");

        EntityKitchenPrtInfo kitchenPrtInfo = new EntityKitchenPrtInfo();
        kitchenPrtInfo.setComId(request.getComId());
        kitchenPrtInfo.setPrtSn(request.getPrtSn());
        kitchenPrtInfo.setPrtKey(request.getPrtKey());
        kitchenPrtInfo.setPrtName(request.getPrtName());
        kitchenPrtInfo.setPrtPhone(request.getPrtPhone());
        kitchenPrtInfo.setRestId(request.getRestId());
        kitchenPrtInfo.setProduct(printerInfoData.getInteger("model") + 1);
        boolean result = kitchenPrtInfoService.saveKitchenInfoPrt(kitchenPrtInfo.getComId(), kitchenPrtInfo);
        if (!result) {
            return ResultUtil.error(ResultEnum.Err_4002, "本地添加失败！");
        }
        return ResultUtil.success(printerInfoData);
    }

    @PostMapping(PayConfigUrl.Url_feieUpdatePtr)
    public Result feieUpdatePtr(@RequestBody KitchenPrinterModifyRequest request) {
        JSONObject update = printerEdit(request.getPrtSn(), request.getPrtName(), request.getPrtPhone());
        if (!"ok".equals(update.getString("msg"))) {
            return ResultUtil.error(ResultEnum.Err_4002, update);
        }
        JSONObject info = printerInfo(request.getPrtSn());
        if (!"ok".equals(info.getString("msg"))) {
            return ResultUtil.error(ResultEnum.Err_4002, info);
        }
        JSONObject printerInfoData = info.getJSONObject("data");

        Boolean result = kitchenPrtInfoService.updateKitchenInfoPrt(request.getComId(), request.getPrtSn(), request.getPrtName(), request.getPrtPhone());
        if (!result) {
            return ResultUtil.error(ResultEnum.Err_4002, "本地修改失败！");
        }
        return ResultUtil.success(printerInfoData);
    }

    @PostMapping(PayConfigUrl.Url_feieRemovePtr)
    public Result feieRemovePtr(@RequestBody KitchenPrinterDeleteRequest request) {
        List<KitchenPrtListDto> kitchenPrtList = kitchenPrtInfoService.kitchenPrtList(request.getComId(), request.getRestId(), request.getPrtId(), 0, 1);
        if (null == kitchenPrtList || 0 == kitchenPrtList.size()) {
            return ResultUtil.error(ResultEnum.Err_1001);
        }
        KitchenPrtListDto kitchenPrtListDto = kitchenPrtList.get(0);
        JSONObject delete = printerDelList(kitchenPrtListDto.getPrtSn());
        if (!"ok".equals(delete.getString("msg"))) {
            return ResultUtil.error(ResultEnum.Err_4002, delete);
        }
        Boolean result = kitchenPrtSchemeService.removeById(kitchenPrtListDto.getKPrtId());
        if (!result) {
            return ResultUtil.error(ResultEnum.Err_4002, "本地删除失败！");
        }
        result = kitchenPrtInfoService.removeById(kitchenPrtListDto.getPrtId());
        if (!result) {
            return ResultUtil.error(ResultEnum.Err_4002, "本地删除失败！");
        }
        return ResultUtil.success(delete);
    }

    @PostMapping(PayConfigUrl.Url_feieCleanSqs)
    public Result feieCleanSqs(@RequestBody KitchenPrinterCleanSqsRequest request) {
        List<KitchenPrtListDto> kitchenPrtList = kitchenPrtInfoService.kitchenPrtList(request.getComId(), request.getRestId(), request.getPrtId(), 0, 1);
        if (null == kitchenPrtList || 0 == kitchenPrtList.size()) {
            return ResultUtil.error(ResultEnum.Err_1001);
        }
        KitchenPrtListDto kitchenPrtListDto = kitchenPrtList.get(0);
        JSONObject delPrinterSqs = delPrinterSqs(kitchenPrtListDto.getPrtSn());
        if (!"ok".equals(delPrinterSqs.getString("msg"))) {
            return ResultUtil.error(ResultEnum.Err_4002, delPrinterSqs);
        }
        return ResultUtil.success(delPrinterSqs);
    }

    @PostMapping(PayConfigUrl.Url_feiePrintMsg)
    public Result feiePrintMsg(@RequestBody JSONObject object) {
        if (null == object.getInteger("type")) {
            object.put("type", 1);
        }
        JSONObject print = printMsg(object.getString("sn"), object.getString("content"), object.getString("times"), object.getInteger("type"));
        log.info("打印结果 3R2aQxfj 【{}】【{}】" , object ,print);
        if (!"ok".equals(print.getString("msg"))) {
            return ResultUtil.error(ResultEnum.Err_4002, print);
        }
        return ResultUtil.success(print);
    }

    @PostMapping(PayConfigUrl.Url_planKitchenPrinter)
    public Result planKitchenPrinter(@RequestBody PlanKitchenPrinterRequest request) {
        log.info("planKitchenPrinter====开始：【{}】", request);

        try {
            if (request.isCheckPrint() && !request.getForcePrint()) {
                if (!redisUtil.lock("KitchenPrinter:" + request.getComId() + ":" + request.getOrderNo(), 6 * 60 * 60)){
                    log.info("planKitchenPrinter====开始：禁止重复打印_1【{}】", request);
                    return ResultUtil.error(ResultEnum.Err_4140);
                }

            }
            if (request.getForcePrint()) {
                if (!redisUtil.lock("KitchenPrinter:Force:" + request.getComId() + ":" + request.getOrderNo(), 5)){
                    log.info("planKitchenPrinter====开始：禁止重复打印_2【{}】", request);
                    return ResultUtil.error(ResultEnum.Err_4140);
                }
            }
            Long comId = request.getComId();
            Long pointId = request.getPointId();
            String orderNo = request.getOrderNo();
            List<PointConfigOnPointInfoDto> pointConfigOnPointInfoDtos = pointConfigService.findPointConfigOnPointInfoByPointId(comId, pointId);
            log.info("planKitchenPrinter====pointConfigOnPointInfoDtos：【{}】,request:【{}】", pointConfigOnPointInfoDtos,request);

            if (pointConfigOnPointInfoDtos == null || pointConfigOnPointInfoDtos.size() == 0) {
                return ResultUtil.error(ResultEnum.Err_4143);
            }

            GetRecordByOrderNoRequest recordByOrderNoRequest = new GetRecordByOrderNoRequest();
            recordByOrderNoRequest.setCompanyId(comId);
            recordByOrderNoRequest.setOrderNo(orderNo);
            Result result = payhandleClientService.getRecordByOrderno(recordByOrderNoRequest);
            log.info("planKitchenPrinter====getRecordByOrderno：【{}】,request:【{}】", result,request);
            if (200 != result.getCode()) {
                return result;
            }
            EntityXfRecordProcess entityXfRecord = JSON.parseObject(JSON.toJSONString(result.getData()), EntityXfRecordProcess.class);

            if (null == entityXfRecord || entityXfRecord.getIfRefund()!=0l) {
                log.info("planKitchenPrinter====消费记录空/已退款：【{}】,request:【{}】", result,request);
                return ResultUtil.error(ResultEnum.Err_1001);
            }
//            if (!Arrays.asList(3,5).contains(entityXfRecord.getConsState()) && !request.getForcePrint()) {
//                return ResultUtil.error(ResultEnum.Err_1001);
//            }
            if(entityXfRecord.getConsState() == 5){

//                if(!request.getForcePrint()){
//                    if(! com.ocom.common.utils.DateUtil.getDate(entityXfRecord.getMealDate()).equals(DateUtils.getDate())){
//                        log.error("planKitchenPrinter====非当天时间报错 9AqDwtMF 【{}】" ,request);
//                        return ResultUtil.error(ResultEnum.Err_3402);
//                    }
//                }

//                GetMealDetailListBRequest configOnShowRequest = new GetMealDetailListBRequest();
//                configOnShowRequest.setMealNo(Integer.valueOf(entityXfRecord.getMealNo()));
//                configOnShowRequest.setPointId(entityXfRecord.getPointId().intValue());
//                configOnShowRequest.setComId(entityXfRecord.getComId());
//                List<MealDetailBVo> mealTimes = mealInfoService.getMealDetailListB(request.getComId(), configOnShowRequest);
//                if (ObjectUtil.isNotEmpty(mealTimes)) {
//                    MealDetailBVo entityXfMealTime = mealTimes.get(0);
//                    entityXfRecord.setMealNo(entityXfMealTime.getMealName());
//                    if(!request.getForcePrint()) {
//                        try {
//                            //餐段时间
//                            long nowLong = new Date().getTime();
//
//                            String date = DateUtils.getDate();
//
//                            //开始 beginDate  - allowday   + allowmin
//                            Date after = DateUtil.getDate(date, "yyyy-MM-dd");
//                            after = DateUtil.getDateBefore(after, entityXfMealTime.getAllowDays());
//                            long begin = after.getTime() + (entityXfMealTime.getAllowMinute() * 60000);
//
//                            Date endD = DateUtil.getDate(date + " " + entityXfMealTime.getStartTime(), "yyyy-MM-dd HH:mm:ss");
//                            long end = endD.getTime() - (entityXfMealTime.getBeforeHour() * 3600000);
//
//                            //截止 begintime - berforeHour
////                        log.info("时间区间:  【{}】【{}】" , begin , end);
//
//                            if (nowLong < begin || nowLong > end) {
//                                log.error("planKitchenPrinter====非当餐时间报错 dF5iP2fp 【{}】", "异常request");
//                                return ResultUtil.error(ResultEnum.Err_4146);
//                            }
//                            entityXfRecord.setMealNo(entityXfMealTime.getMealName());
//                        } catch (ParseException e) {
//
//                        }
//                    }
//                }


                try{
                    GetMealDetailListBRequest configOnShowRequest = new GetMealDetailListBRequest();
                    configOnShowRequest.setMealNo(Integer.valueOf(entityXfRecord.getMealNo()));
                    configOnShowRequest.setPointId(entityXfRecord.getPointId().intValue());
                    configOnShowRequest.setComId(entityXfRecord.getComId());
                    List<MealDetailBVo> mealTimes = mealInfoService.getMealDetailListB(request.getComId(), configOnShowRequest);

                    MealDetailBVo entityXfMealTime = mealTimes.get(0);
                    entityXfRecord.setMealNo(entityXfMealTime.getMealName());
                }catch (Exception e){

                }


            }

            EntityXfRecordProcessExtend entityXfRecordProcessExtend = this.xfRecordProcessExtendService.getByOrderNo(entityXfRecord.getComId(),entityXfRecord.getOrderNo());
            result = payhandleClientService.getGoodsListProcessOnDishes(comId, orderNo);
            log.info("planKitchenPrinter====getByOrderNo：【{}】,request【{}】", result,request);
            if (200 != result.getCode()) {
                return result;
            }
            List<GoodsListProcessDishesDto> goodsListProcessDishesDtos = JSON.parseArray(JSON.toJSONString(result.getData()), GoodsListProcessDishesDto.class);

            StringBuilder strArea = getStrArea(comId, entityXfRecord);

            StringBuilder strDishClass = getStrDishClass(goodsListProcessDishesDtos);

            for (PointConfigOnPointInfoDto pointInfoDto : pointConfigOnPointInfoDtos) {

                StringBuilder strDishes = getStrDishes(goodsListProcessDishesDtos);
                log.info("planKitchenPrinter====strArea：【{}】", strArea.toString());
                List<GetSchemeOnPrtInfoDto> masterPointInfo = kitchenPrtSchemeService.getSchemeOnPrtInfo(comId, pointInfoDto.getRestId(), 1, strArea.toString());

                strArea.append(strDishClass).append(strDishes);
                log.info("planKitchenPrinter====strArea2：【{}】", strArea.toString());
                List<GetSchemeOnPrtInfoDto> slavePointInfo = kitchenPrtSchemeService.getSchemeOnPrtInfo(comId, pointInfoDto.getRestId(), 2, strArea.toString());

                //2个类型打印机合并  同型号兼容
                masterPointInfo.addAll(slavePointInfo);

                List<GetSchemeOnPrtInfoDto> PendingMasterPoint = masterPointInfo.stream().filter(e -> 1 == e.getIfMaster()).collect(Collectors.toList());
                List<GetSchemeOnPrtInfoDto> PendingSlavePoint = masterPointInfo.stream().filter(e -> 1 == e.getIfDish()).collect(Collectors.toList());
//                slavePointInfo.addAll(PendingSlavePoint);

                List<Order> orderList = goodsListProcessDishesDtos.stream().map(goods -> new Order(goods.getDishesName(), AcpService.stringAmount(goods.getUnitPrice().toString()), goods.getWeightNumber(), String.valueOf(goods.getDishesId()), goods.getDishesClassId())).collect(Collectors.toList());

                //product 3 的打印机 小票
                List<GetSchemeOnPrtInfoDto> masterPointInfo1 = kitchenPrtSchemeService.getSchemeOnPrtInfo(comId, pointInfoDto.getRestId(), 3, strArea.toString());
                //打总单
                List<GetSchemeOnPrtInfoDto> PendingMasterPoint3 = masterPointInfo1.stream().filter(e -> 1 == e.getIfMaster()).collect(Collectors.toList());


                log.info("planKitchenPrinter====orderList：【{}】", orderList);
                log.info("planKitchenPrinter====PendingMasterPoint：【{}】", PendingMasterPoint);
                log.info("planKitchenPrinter====slavePointInfo：【{}】", PendingSlavePoint);

                for (GetSchemeOnPrtInfoDto schemeOnPrtInfoDto : PendingMasterPoint) {
                    StringBuilder content = getMasterPrintContent(orderList, pointInfoDto, entityXfRecord, schemeOnPrtInfoDto,entityXfRecordProcessExtend);

                    log.info("planKitchenPrinter====pendingSchemeOnPrtInfoDto：【{}】", content);
                    saveRecord(comId, orderNo, 1, content, schemeOnPrtInfoDto, 1);
                }

                for (GetSchemeOnPrtInfoDto schemeOnPrtInfoDto : PendingSlavePoint) {
                    StringBuilder content = getSlavePrintContent(orderList, pointInfoDto, entityXfRecord, schemeOnPrtInfoDto,entityXfRecordProcessExtend);

                    log.info("planKitchenPrinter====slaveSchemeOnPrtInfoDto：【{}】", content);
                    saveRecord(comId, orderNo, 2, content, schemeOnPrtInfoDto, 1);
                }

                for (GetSchemeOnPrtInfoDto schemeOnPrtInfoDto : PendingMasterPoint3) {
                    StringBuilder content = getMasterPrintContent1(orderList, pointInfoDto, entityXfRecord, schemeOnPrtInfoDto);

                    log.info("PendingMasterPoint3====pendingSchemeOnPrtInfoDto：【{}】", content);
                    saveRecord(comId, orderNo, 1, content, schemeOnPrtInfoDto, 3);
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("planKitchenPrinter====异常：【{}】,【{}】", e.getMessage(), e);
            return ResultUtil.error(ResultEnum.Err_900);
        }
        return ResultUtil.success();
    }


    private StringBuilder getStrDishes(List<GoodsListProcessDishesDto> goodsList) {
        List<Long> dishesIds = goodsList.stream().map(e -> e.getDishesId()).collect(Collectors.toList());
        StringBuilder strDishes = new StringBuilder(" and ( S.dishes = '' or S.dishes IS null ");
        for (Long dishesId : dishesIds) {
            strDishes.append(" or ");
            strDishes.append(" find_in_set(");
            strDishes.append(dishesId);
            strDishes.append(", S.dishes)");
        }
        strDishes.append(")");
        return strDishes;
    }

    private StringBuilder getStrDishClass(List<GoodsListProcessDishesDto> goodsList) {
        List<String> dishesClassIds = goodsList.stream().map(e -> e.getDishesClassId()).collect(Collectors.toList());
        StringBuilder strDishClass = new StringBuilder(" and ( S.dish_class = '' or S.dish_class IS null ");
        for (String dishesClassId : dishesClassIds) {
            strDishClass.append(" or ");
            strDishClass.append(" find_in_set(");
            strDishClass.append(dishesClassId);
            strDishClass.append(", S.dish_class)");
        }
        strDishClass.append(")");
        return strDishClass;
    }

    private StringBuilder getStrArea(Long comId, EntityXfRecordProcess entityXfRecord) {
        StringBuilder strArea = new StringBuilder("( S.tables = '-1' or S.tables = '' or S.tables IS null ");
        strArea.append(" or ");
        strArea.append(" find_in_set(");
        strArea.append(entityXfRecord.getReceiptId());
        strArea.append(", S.tables)");
        if (0 < entityXfRecord.getReceiptId()) {
            GetAdReceiptInfoRequest getAdReceiptInfoRequest = new GetAdReceiptInfoRequest();
            getAdReceiptInfoRequest.setComId(comId);
            getAdReceiptInfoRequest.setReceiptId(entityXfRecord.getReceiptId().intValue());
            List<EntityReceiptAddress> receiptAddresses = receiptAddressService.getAdReceiptInfo(comId, getAdReceiptInfoRequest);
            String[] receiptOrgins = receiptAddresses.stream().map(e -> e.getReceiptOrgin().split(",")).flatMap(Arrays::stream).toArray(String[]::new);
            for (String orgin : receiptOrgins) {
                if (StringUtils.isNotBlank(orgin) && 0 != Integer.valueOf(orgin)) {
                    strArea.append(" or ");
                    strArea.append(" find_in_set(");
                    strArea.append(orgin);
                    strArea.append(", S.tables)");
                }
            }
        }

        strArea.append(")");
        return strArea;
    }

    private StringBuilder getMasterPrintContent(List<Order> orderList, PointConfigOnPointInfoDto pointInfoDto, EntityXfRecordProcess entityXfRecord, GetSchemeOnPrtInfoDto schemeOnPrtInfoDto,EntityXfRecordProcessExtend entityXfRecordProcessExtend) {
        StringBuilder content = new StringBuilder();
        try {
            if (1 == schemeOnPrtInfoDto.getIfRestName()) {
                content.append("<CB>");
                content.append(pointInfoDto.getPointName());
                content.append("</CB><BR>");
            }

            if (null != entityXfRecord.getReceiptId()) {
                content.append("<B><BOLD>");
                switch (entityXfRecord.getReceiptId().intValue()) {
                    case -1:
                        content.append("点餐号：");
                        content.append(entityXfRecord.getReceiptNo());
                        break;
                    case 0:
                        content.append("取餐号：");
                        content.append(entityXfRecord.getReceiptNo());
                        break;
                    default:
                        content.append("配送地址：");
                        content.append(entityXfRecord.getReceiptName());
                }
                content.append("</B></BOLD>");
                content.append("<BR>");
            }


            if (entityXfRecord.getPId() != null && entityXfRecord.getPId() > 0l) {
                content.append("<B><BOLD>点餐人：");
                content.append(entityXfRecord.getPName() + "(" + entityXfRecord.getPCode() + ")");
                content.append("</B></BOLD><BR>");
            }

            if (entityXfRecord.getConsState() == 5) {
                content.append("<B><BOLD>订餐餐段：");
                content.append(DateUtil.getDate(entityXfRecord.getMealDate()) + "###" + entityXfRecord.getMealNo() + ")");
                content.append("</B></BOLD><BR>");
            }

            //菜品分类列表
            if (StringUtils.isNotBlank(schemeOnPrtInfoDto.getDishClass())) {
                String[] dishClassIds = schemeOnPrtInfoDto.getDishClass().split(",");
                List<String> list = Arrays.asList(dishClassIds);

                orderList = orderList.stream().filter(e -> list.contains(e.getDishesClassId())).collect(Collectors.toList());
            }

            //菜品列表
            if (StringUtils.isNotBlank(schemeOnPrtInfoDto.getDishes())) {
                String[] dishIds = schemeOnPrtInfoDto.getDishes().split(",");
                List<String> list = Arrays.asList(dishIds);

                orderList = orderList.stream().filter(e -> list.contains(e.getDishesId())).collect(Collectors.toList());
            }

            content.append("名称　　　　　 单价  数量 金额<BR>");
            content.append(PrintUtil4.getOrder(orderList, 14, 6, 3, 6));

            content.append("单号：");
            content.append(entityXfRecord.getOrderNo());
            content.append("<BR>");

            if (entityXfRecord.getComId() == 693l) {
                try {
                    content.append("<BOLD>优惠金额：");
                    content.append((double) entityXfRecord.getDiscount() / -100);
                    content.append("</BOLD><BR>");
                } catch (Exception e) {
                    log.info("打印异常1 【{}】", e);
                }
                if(ObjectUtil.isNotEmpty(entityXfRecordProcessExtend) && ObjectUtil.isNotEmpty(entityXfRecordProcessExtend.getReceiptPrice())){
                    content.append("<BOLD>配送费：");
                    content.append((double) entityXfRecordProcessExtend.getReceiptPrice() / -100);
                    content.append("</BOLD><BR>");
                }
                try {
                    content.append("<BOLD>实际扣款金额：");
                    content.append((double) entityXfRecord.getRealMoney() / -100);
                    content.append("</BOLD><BR>");
                } catch (Exception e) {
                    log.info("打印异常2【{}】", e);
                }
            }

//            if (entityXfRecord.getReceiptId()!=null && entityXfRecord.getReceiptId()>0 ) {
//                content.append("配送地址：");
//                content.append(entityXfRecord.getReceiptName());
//                content.append("<BR>");
//            }

            content.append("点餐时间：");
            content.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(entityXfRecord.getConsTime()));
            content.append("<BR>");

            content.append("备注：");
            content.append(entityXfRecord.getReserved3());
            content.append("<BR>");

            if (entityXfRecord.getComId() == 693l) {
                try {
                    content.append("<QR>");

                    content.append("order_no=");
                    content.append(entityXfRecord.getOrderNo());
                    content.append("</QR>");
                } catch (Exception e) {
                    log.info("打印异常2【{}】", e);
                }
            }
//            content.append("打印类型：总单");
//            content.append("<BR>");

//            content.append("<QR>http://gzh.ocom30.com/</QR>");

        } catch (Exception e) {
            e.printStackTrace();
            log.info("组装订单内容失败！【{}】", e);
        }
        return content;
    }


    //分单
    private StringBuilder getSlavePrintContent(List<Order> orderList, PointConfigOnPointInfoDto pointInfoDto, EntityXfRecordProcess entityXfRecord, GetSchemeOnPrtInfoDto schemeOnPrtInfoDto,EntityXfRecordProcessExtend entityXfRecordProcessExtend) {
        StringBuilder content = new StringBuilder();
        try {

            if (null != entityXfRecord.getReceiptId()) {
                content.append("<B><BOLD>");
                switch (entityXfRecord.getReceiptId().intValue()) {
                    case -1:
                        content.append("点餐号：");
                        content.append(entityXfRecord.getReceiptNo());
                        break;
                    case 0:
                        content.append("取餐号：");
                        content.append(entityXfRecord.getReceiptNo());
                        break;
                    default:
                        content.append("餐台号：");
                        content.append(entityXfRecord.getReceiptName());
                }
                content.append("</B></BOLD>");
                content.append("<BR>");
            }

            if (entityXfRecord.getPId() != null && entityXfRecord.getPId() > 0l) {
                content.append("<B><BOLD>点餐人：");
                content.append(entityXfRecord.getPName() + "(" + entityXfRecord.getPCode() + ")");
                content.append("</B></BOLD><BR>");
            }

            if (entityXfRecord.getConsState() == 5) {
                content.append("<B><BOLD>订餐餐段：");
                content.append(DateUtil.getDate(entityXfRecord.getMealDate()) + "###" + entityXfRecord.getMealNo() + ")");
                content.append("</B></BOLD><BR>");
            }

            //菜品分类列表
            if (StringUtils.isNotBlank(schemeOnPrtInfoDto.getDishClass())) {
                String[] dishClassIds = schemeOnPrtInfoDto.getDishClass().split(",");
                List<String> list = Arrays.asList(dishClassIds);

                orderList = orderList.stream().filter(e -> list.contains(e.getDishesClassId())).collect(Collectors.toList());
            }

            //菜品列表
            if (StringUtils.isNotBlank(schemeOnPrtInfoDto.getDishes())) {
                String[] dishIds = schemeOnPrtInfoDto.getDishes().split(",");
                List<String> list = Arrays.asList(dishIds);

                orderList = orderList.stream().filter(e -> list.contains(e.getDishesId())).collect(Collectors.toList());
            }

            content.append("名称　　　　　 单价  数量 金额<BR>");
            content.append(PrintUtil4.getOrder(orderList, 14, 6, 3, 6));

            content.append("单号：");
            content.append(entityXfRecord.getOrderNo());
            content.append("<BR>");

            if (entityXfRecord.getComId() == 693l) {
                try {
                    content.append("<BOLD>优惠金额：");
                    content.append((double) entityXfRecord.getDiscount() / -100);
                    content.append("</BOLD><BR>");
                } catch (Exception e) {
                    log.info("打印异常3 【{}】", e);
                }
                try {
                    content.append("<BOLD>实际扣款金额：");
                    content.append((double) entityXfRecord.getRealMoney() / -100);
                    content.append("</BOLD><BR>");
                } catch (Exception e) {
                    log.info("打印异常4 【{}】", e);
                }
            }


            content.append("点餐时间：");
            content.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(entityXfRecord.getConsTime()));
            content.append("<BR>");
            if (entityXfRecord.getComId() == 693l) {
                try {
                    content.append("<QR>");

                    content.append("order_no=");
                    content.append(entityXfRecord.getOrderNo());
                    content.append("</QR>");
                } catch (Exception e) {
                    log.info("打印异常2【{}】", e);
                }
            }
//            content.append("打印类型：分单");
//            content.append("<BR>");

//            content.append("<QR>http://gzh.ocom30.com/</QR>");

        } catch (Exception e) {
            e.printStackTrace();
            log.info("组装订单内容失败！【{}】", e);
        }
        return content;
    }

    private Result goPrint(String content, String prtSn, Integer type) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("sn", prtSn);
        jsonObject.put("content", content);
        jsonObject.put("times", "1");
        jsonObject.put("type", type);

        return feiePrintMsg(jsonObject);
    }

    /**
     * @param comId
     * @param orderNo
     * @param printFormat
     * @param content
     * @param schemeOnPrtInfoDto
     * @param type               1打印机 2小票机  3标签机
     */
    private void saveRecord(Long comId, String orderNo, Integer printFormat, StringBuilder content, GetSchemeOnPrtInfoDto schemeOnPrtInfoDto, Integer type) {
        try {
            EntityKitchenPrtRecord record = new EntityKitchenPrtRecord();
            record.setComId(comId);
            record.setOrderNo(orderNo);
            record.setPrtId(schemeOnPrtInfoDto.getPrtId());
            record.setPrintFormat(printFormat);
            record.setPrintContent(content.toString());

            Result result = goPrint(content.toString(), schemeOnPrtInfoDto.getPrtSn(), type);
            if (200 == result.getCode()) {
                record.setStatus(2);
                JSONObject printJsonObject = JSON.parseObject(JSON.toJSONString(result.getData()));
                record.setPrintOrderId(printJsonObject.getString("data"));
            } else {
                record.setStatus(1);
            }

            kitchenPrtRecordService.saveRecord(comId, record);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("保存打印记录失败：【{}】", e);
        }

    }


    /*
     * 飞鹅批量添加打印机，Open_printerAddlist
     * * */
    public static JSONObject printerAddlist(String prtSn, String prtKey, String prtName, String phonenum) {
        final String S_TIME = String.valueOf(System.currentTimeMillis() / 1000);

        String key = USER + U_KEY + S_TIME;
        log.info("key:" + key);
        String sig = DigestUtils.sha1Hex(key);
        log.info("sig:" + sig);

        List<String> contentList = new ArrayList<>();
        contentList.add(prtSn);
        contentList.add(prtKey);
        contentList.add(prtName);
        contentList.add(phonenum);

        String content = String.join("#", contentList);

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("user", USER));
        nvps.add(new BasicNameValuePair("stime", S_TIME));
        nvps.add(new BasicNameValuePair("sig", sig));
        nvps.add(new BasicNameValuePair("apiname", "Open_printerAddlist"));//固定值,不需要修改

        nvps.add(new BasicNameValuePair("printerContent", content));
        log.info("param:" + nvps);

        JSONObject result = getResult(doPost(nvps));
        log.info("result:" + result);
        return result;
    }

    /*
     * 修改打印机信息，Open_printerEdit
     * * */
    public static JSONObject printerEdit(String sn, String name, String phonenum) {
        final String S_TIME = String.valueOf(System.currentTimeMillis() / 1000);

        String key = USER + U_KEY + S_TIME;
        log.info("key:" + key);
        String sig = DigestUtils.sha1Hex(key);
        log.info("sig:" + sig);


        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("user", USER));
        nvps.add(new BasicNameValuePair("stime", S_TIME));
        nvps.add(new BasicNameValuePair("sig", sig));
        nvps.add(new BasicNameValuePair("apiname", "Open_printerEdit"));//固定值,不需要修改

        nvps.add(new BasicNameValuePair("sn", sn));
        nvps.add(new BasicNameValuePair("name", name));
        nvps.add(new BasicNameValuePair("phonenum", phonenum));
        log.info("param:" + nvps);

        JSONObject result = doPost(nvps);
        log.info("result:" + result);
        return result;
    }

    /*
     * 删除批量打印机，Open_printerDelList
     * * */
    public static JSONObject printerDelList(String sn) {
        final String S_TIME = String.valueOf(System.currentTimeMillis() / 1000);

        String key = USER + U_KEY + S_TIME;
        log.info("key:" + key);
        String sig = DigestUtils.sha1Hex(key);
        log.info("sig:" + sig);


        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("user", USER));
        nvps.add(new BasicNameValuePair("stime", S_TIME));
        nvps.add(new BasicNameValuePair("sig", sig));
        nvps.add(new BasicNameValuePair("apiname", "Open_printerDelList"));//固定值,不需要修改

        nvps.add(new BasicNameValuePair("snlist", sn));
        log.info("param:" + nvps);

        JSONObject result = doPost(nvps);
        log.info("result:" + result);
        return result;
    }

    /*
     * 获取某台打印机信息，Open_printerInfo
     * * */
    public static JSONObject printerInfo(String sn) {
        final String S_TIME = String.valueOf(System.currentTimeMillis() / 1000);

        String key = USER + U_KEY + S_TIME;
        log.info("key:" + key);
        String sig = DigestUtils.sha1Hex(key);
        log.info("sig:" + sig);

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("user", USER));
        nvps.add(new BasicNameValuePair("stime", S_TIME));
        nvps.add(new BasicNameValuePair("sig", sig));
        nvps.add(new BasicNameValuePair("apiname", "Open_printerInfo"));//固定值,不需要修改

        nvps.add(new BasicNameValuePair("sn", sn));
        log.info("param:" + nvps);

        JSONObject result = doPost(nvps);
        log.info("result:" + result);
        return result;
    }

    /*
     * 打印订单，Open_printMsg
     * * */
    public static JSONObject printMsg(String sn, String content, String times, Integer type) {
        final String S_TIME = String.valueOf(System.currentTimeMillis() / 1000);

        String key = USER + U_KEY + S_TIME;
        log.info("key:" + key);
        String sig = DigestUtils.sha1Hex(key);
        log.info("sig:" + sig);


        //标签说明：
        //单标签:
        //"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
        //"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
        //成对标签：
        //"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
        //<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐
        //拼凑订单内容时可参考如下格式
        //根据打印纸张的宽度，自行调整内容的格式，可参考下面的样例格式

//        content = "<CB>测试打印</CB><BR>";
//        content.append("名称　　　　　 单价  数量 金额<BR>";
//        content.append("--------------------------------<BR>";
//        content.append("饭　　　　　　 1.0    1   1.0<BR>";
//        content.append("炒饭　　　　　 10.0   10  10.0<BR>";
//        content.append("蛋炒饭　　　　 10.0   10  100.0<BR>";
//        content.append("鸡蛋炒饭　　　 100.0  1   100.0<BR>";
//        content.append("番茄蛋炒饭　　 1000.0 1   100.0<BR>";
//        content.append("西红柿蛋炒饭　 1000.0 1   100.0<BR>";
//        content.append("西红柿鸡蛋炒饭 100.0  10  100.0<BR>";
//        content.append("备注：加辣<BR>";
//        content.append("--------------------------------<BR>";
//        content.append("合计：xx.0元<BR>";
//        content.append("送货地点：广州市南沙区xx路xx号<BR>";
//        content.append("联系电话：13888888888888<BR>";
//        content.append("订餐时间：2016-08-08 08:08:08<BR>";
//        content.append("<QR>http://www.dzist.com</QR>";


        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("user", USER));
        nvps.add(new BasicNameValuePair("stime", S_TIME));
        nvps.add(new BasicNameValuePair("sig", sig));


        if (type == 1) {
            //打印机
            nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
        } else if (type == 2) {
            //小票机
            nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
        } else if (type == 3) {
            //标签
            nvps.add(new BasicNameValuePair("apiname", "Open_printLabelMsg"));//固定值,不需要修改
        }

        nvps.add(new BasicNameValuePair("content", content));
        nvps.add(new BasicNameValuePair("sn", sn));
        nvps.add(new BasicNameValuePair("times", times));//打印联数
        log.info("param:" + nvps);

        JSONObject result = doPost(nvps);
        log.info("result:" + result);
        return result;
    }

    /*
     * 清空待打印队列，Open_delPrinterSqs
     * * */
    public static JSONObject delPrinterSqs(String sn) {
        final String S_TIME = String.valueOf(System.currentTimeMillis() / 1000);

        String key = USER + U_KEY + S_TIME;
        log.info("key:" + key);
        String sig = DigestUtils.sha1Hex(key);
        log.info("sig:" + sig);

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("user", USER));
        nvps.add(new BasicNameValuePair("stime", S_TIME));
        nvps.add(new BasicNameValuePair("sig", sig));
        nvps.add(new BasicNameValuePair("apiname", "Open_delPrinterSqs"));//固定值,不需要修改

        nvps.add(new BasicNameValuePair("sn", sn));
        log.info("param:" + nvps);

        JSONObject result = doPost(nvps);
        log.info("result:" + result);
        return result;
    }


    private static JSONObject doPost(List<NameValuePair> nvps) {

        //通过POST请求，发送打印信息到服务器
        RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(30000)//读取超时
                .setConnectTimeout(30000)//连接超时
                .build();

        CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultRequestConfig(requestConfig)
                .build();

        HttpPost post = new HttpPost(URL);

        CloseableHttpResponse response = null;
        JSONObject result = null;
        try {
            post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
            response = httpClient.execute(post);
            int statecode = response.getStatusLine().getStatusCode();
            if (statecode == 200) {
                HttpEntity httpentity = response.getEntity();
                if (httpentity != null) {
                    result = JSON.parseObject(unicodeDecode(EntityUtils.toString(httpentity)));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (response != null) {
                    response.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                post.abort();
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return result;

    }

    public static String unicodeDecode(String string) {
        Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
        Matcher matcher = pattern.matcher(string);
        char ch;
        while (matcher.find()) {
            ch = (char) Integer.parseInt(matcher.group(2), 16);
            string = string.replace(matcher.group(1), ch + "");
        }
        return string;
    }

    private static JSONObject getResult(JSONObject result) {

        if (null != result && "ok".equals(result.get("msg"))) {
            JSONObject data = JSON.parseObject(result.getString("data"));
            JSONArray ok = JSON.parseArray(data.getString("ok"));
            JSONArray no = JSON.parseArray(data.getString("no"));
            if (null != data && 0 == no.size() && 0 < ok.size()) {
                result.put("code", 200);
                result.put("message", ok);
            } else {
                result.put("code", 500);
                result.put("message", no);
            }
        }
        return result;
    }

//    public static void main(String[] args) {
////        printerAddlist("520500839","72rwtuxq","测试机器");
////        printMsg("520500839","","1");
//        printerInfo("520500839");//result:{"msg":"ok","ret":0,"data":{"model":0,"status":1}
//
//    }


    @GetMapping(PayConfigUrl.Url_kitchenPrtTimer)
    public Result kitchenPrtTimer() {
        kitchenPrtTimerHandle(100l);
        kitchenPrtTimerHandle(600l);
//        List<KitchenPrtListDto> list = kitchenPrtInfoService.kitchenPrtList(600l);

        return ResultUtil.success();
    }


    private void kitchenPrtTimerHandle(Long companyId) {
//        List<KitchenPrtListDto> list = kitchenPrtInfoService.kitchenPrtList(companyId, 1);
        List<KitchenPrtListDto> list2 = kitchenPrtInfoService.kitchenPrtList(companyId, 3);

        /*
        ALTER TABLE `kitchen_prt_scheme`
ADD COLUMN `if_order_sum_dishes`  tinyint(4) NULL DEFAULT 0 AFTER `if_order_sum`;
         */

//        if(list != null && list.size()>0){
//            handleListDishes(list,1,1);
//        }
//        if(list2 != null && list2.size()>0){
//            handleListDishes(list2,1,3);
//        }

//        if (list != null && list.size() > 0) {
//            handleListCount(list, 0, 1);
//        }
        if (list2 != null && list2.size() > 0) {
            handleListCount(list2, 0, 3);
        }

    }

    /**
     * @param list
     * @param type    0定时的  1 即时打印
     * @param product 1 打印机  3标签机
     */
    private void handleListDishes(List<KitchenPrtListDto> list, Integer type, Integer product) {
        for (KitchenPrtListDto kitchenPrtListDto : list) {
            try {
                List<EntityXfMealTime> xfMealTimes = xfMealTimeService.getMealTimeList(kitchenPrtListDto.getComId());
                for (EntityXfMealTime entityXfMealTime : xfMealTimes) {

                    String esrTime = DateUtils.getDate() + " " + entityXfMealTime.getBeginTime();
                    Date start = DateUtils.getDate(esrTime, "yyyy-MM-dd HH:mm:ss");
                    long timestamp = start.getTime() - 3600000l * entityXfMealTime.getBeforeHour().longValue();

                    if (type == 0) {
                        long milliseconds = timestamp - System.currentTimeMillis();
                        long minutes = milliseconds / (60 * 1000);

                        //   System.out.println("Minutes difference: " + minutes);

                        //不需要打印的 不在时间内
                        if (minutes > 0 || minutes < -10l) {
                            continue;
                        }
                    }


                    GetPointMealSendReportsXMRequest request = new GetPointMealSendReportsXMRequest();
                    request.setComId(entityXfMealTime.getComId());
                    request.setPointId(kitchenPrtListDto.getPointId());
                    request.setMealDate(DateUtils.getDate());
                    request.setMealNo(Integer.valueOf(entityXfMealTime.getMealNo()));

                    Result mealSendReportsXMByGoods = xfRecordFeign.getMealSendReportsXMByGoods(request);
                    if (200 != mealSendReportsXMByGoods.getCode()) {
                        continue;
                    }

                    JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(mealSendReportsXMByGoods.getData()));
                    List<EntityXfGoodListDishes> mealSendReports = JSON.parseArray(JSON.toJSONString(jsonObject.get("list")), EntityXfGoodListDishes.class);

                    if (mealSendReports == null || mealSendReports.size() == 0) {
                        continue;
                    }


                    GetAdReceiptInfoRequest getAdReceiptInfoRequest = new GetAdReceiptInfoRequest();
                    getAdReceiptInfoRequest.setComId(request.getComId());
                    List<EntityReceiptAddress> adReceiptInfo = receiptAddressService.getAdReceiptInfo(request.getComId(), getAdReceiptInfoRequest);
                    Map<Integer, EntityReceiptAddress> receiptMap = adReceiptInfo.stream().collect(Collectors.toMap(EntityReceiptAddress::getReceiptId, EntityReceiptAddress -> EntityReceiptAddress));

                    List<EntityXfGoodListDishes> collect = mealSendReports.stream().map(e -> {
                        EntityReceiptAddress entityReceiptAddress = receiptMap.get(e.getReceiptId());
                        if (null != entityReceiptAddress) {
                            e.setReceiptName(entityReceiptAddress.getReceiptName());
                            e.setRemark(entityReceiptAddress.getRemark());
                        }
                        return e;
                    }).collect(Collectors.toList());

                    for (EntityXfGoodListDishes entityXfGoodListDishes : collect) {

                        StringBuilder content = new StringBuilder();
                        if (product == 1) {
                            content.append("<L><BOLD>日期:" + DateUtils.dateToStr(new Date(timestamp)) + "</BOLD></L><BR>");
                            content.append("<L><BOLD>送达地点:" + entityXfGoodListDishes.getReceiptName() + "</BOLD></L><BR>");
                            content.append("<L><BOLD>联系人:" + entityXfGoodListDishes.getRemark() + "</BOLD></L><BR>");
//                        content.append("<L><BOLD>送达地点:</BOLD>"+entityXfGoodListDishes.getReceiptName()+"<BR>");
                            content.append("<L><BOLD>份数/套餐类别:" + entityXfGoodListDishes.getWeightNumber() + "份," + entityXfGoodListDishes.getDishesName() + "</BOLD></L><BR>");
                            content.append("<L><BOLD>打印时间:" + DateUtils.dateToStr(new Date()) + "</BOLD></L><BR>");
                            content.append("--------------------------------<BR>");
                        }
                        if (product == 3) {

                            Integer line = 1;
//                            content.append("<SIZE>40,30</SIZE>");


                            content.append("<TEXT x=\"5\" y=\"2\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                            content.append("科室名称:" + entityXfGoodListDishes.getReceiptName());
                            content.append("</TEXT>");


                            content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                            line++;
                            content.append("联系人:" + entityXfGoodListDishes.getRemark());
                            content.append("</TEXT>");

                            content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                            line++;
                            content.append("套餐/类别:" + entityXfGoodListDishes.getWeightNumber() + "份," + entityXfGoodListDishes.getDishesName());
                            content.append("</TEXT>");

                            content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                            line++;
                            content.append("打印时间:" + DateUtils.dateToStr(new Date()));
                            content.append("</TEXT>");
                        }


                        String orderNo = request.getMealDate() + "#" + request.getMealNo() + "#" + entityXfGoodListDishes.getReceiptId() + "#" + entityXfGoodListDishes.getDishesId();

                        if (type == 0) {
                            //redis判断
                            if (!redisUtil.lock("KitchenPrinter:" + request.getComId() + "#" + orderNo, 60 * 60)) {
                                continue;
                            }
                        } else {
                            orderNo = request.getMealDate() + "#" + request.getMealNo() + "#" + entityXfGoodListDishes.getReceiptId() + "#" + RandomUtil.getRandomString(8);
                        }

                        GetSchemeOnPrtInfoDto schemeOnPrtInfoDto = JSON.parseObject(JSON.toJSONString(kitchenPrtListDto), GetSchemeOnPrtInfoDto.class);

                        saveRecord(entityXfMealTime.getComId(), orderNo, 4, content, schemeOnPrtInfoDto, product);

                        log.info("打印4++++" + content.toString());

                    }
                }
            } catch (Exception e) {
                log.error("打印统计异常 【{}】【{}】", kitchenPrtListDto, e);
            }

        }
    }


    @PostMapping(PayConfigUrl.Url_kitchenPrtByComId)
    public Result kitchenPrtByComId(@RequestBody GetPointMealSendReportsRequest request) {

        HashMap<String, Object> map = new HashMap<>();
        Result<List<GetPointMealSendVo>> pointMealSend = xfRecordFeign.getPointMealSend(request);
        List<EntityXfMealInfo> mealInfos = mealInfoService.GetMealNameInfo(null, request.getComId(), null, null);

//        boolean flag= false;

        //餐段
        Map<String, String> stringMap = mealInfos.stream().collect(Collectors.toMap(e -> e.getMealNo(),
                e -> e.getMealName(),
                (e1, e2) -> e1));

        //消费点查某天某餐
        List<String> pointIds = new ArrayList<>();

        if (pointMealSend.getData().size() > 0) {

            GetAdReceiptInfoRequest getAdReceiptInfoRequest = new GetAdReceiptInfoRequest();
            getAdReceiptInfoRequest.setComId(request.getComId());
            List<EntityReceiptAddress> adReceiptInfo = receiptAddressService.getAdReceiptInfo(request.getComId(), getAdReceiptInfoRequest);
            Map<Integer, EntityReceiptAddress> receiptMap = adReceiptInfo.stream().collect(Collectors.toMap(EntityReceiptAddress::getReceiptId, EntityReceiptAddress -> EntityReceiptAddress));

            for (GetPointMealSendVo getPointMealSendVo : pointMealSend.getData()) {

                if (getPointMealSendVo.getDcTimes() == null || getPointMealSendVo.getDcTimes() == 0) {
                    continue;
                }

                //打印的机器
                List<GetSchemeOnPrtInfoDto> masterPointInfo = kitchenPrtSchemeService.getCountMachList(request.getComId(), 1);

                List<GetSchemeOnPrtInfoDto> masterPointInfo1 = kitchenPrtSchemeService.getCountMachList(request.getComId(), 3);

                //同时为空
                if ((masterPointInfo == null || masterPointInfo.size() == 0) &&
                        (masterPointInfo1 == null || masterPointInfo1.size() == 0)) {
                    continue;
                }

                GetPointMealSendReportsXMRequest getPointMealSendReportsXMRequest = new GetPointMealSendReportsXMRequest();
                getPointMealSendReportsXMRequest.setComId(request.getComId());
                getPointMealSendReportsXMRequest.setPointId(getPointMealSendVo.getPointId());
                getPointMealSendReportsXMRequest.setMealDate(DateUtils.getStrDate(getPointMealSendVo.getMealDate(), "yyyy-MM-dd"));
                getPointMealSendReportsXMRequest.setMealNo(Integer.valueOf(getPointMealSendVo.getMealNo()));
                if (request.getReceiptId() != null) {
                    getPointMealSendReportsXMRequest.setReceiptId(request.getReceiptId().intValue());
                }

                //判断消费点是否查询过
                String key2 = getPointMealSendReportsXMRequest.getPointId() + "#" + getPointMealSendReportsXMRequest.getMealDate()
                        + "#" + getPointMealSendReportsXMRequest.getMealNo();
                if (pointIds.contains(key2)) {
                    continue;
                }
                pointIds.add(key2);

                //某个消费点 某天某餐 各取餐点信息
                Result mealSendReportsXMByGoods = xfRecordFeign.getMealSendReportsXMByGoods(getPointMealSendReportsXMRequest);
                if (200 != mealSendReportsXMByGoods.getCode()) {
                    continue;
                }
                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(mealSendReportsXMByGoods.getData()));
                List<EntityXfGoodListDishes> mealSendReports = JSON.parseArray(JSON.toJSONString(jsonObject.get("list")), EntityXfGoodListDishes.class);

                if (mealSendReports == null || mealSendReports.size() == 0) {
                    continue;
                }

                //取餐点对应订单
                Map<Integer, List<Order>> integerList = new HashMap<>();

                //订单处理  区分取餐点
                for (EntityXfGoodListDishes entityXfGoodListDishes : mealSendReports) {
                    Order order = new Order(entityXfGoodListDishes.getDishesName(), "0", entityXfGoodListDishes.getWeightNumber().toString());
                    if (!integerList.containsKey(entityXfGoodListDishes.getReceiptId())) {
                        List<Order> orderList1 = new ArrayList<>();
                        orderList1.add(order);
                        integerList.put(entityXfGoodListDishes.getReceiptId(), orderList1);
                    } else {
                        integerList.get(entityXfGoodListDishes.getReceiptId()).add(order);
                    }
                }

                if (masterPointInfo != null && masterPointInfo.size() > 0) {
                    for (GetSchemeOnPrtInfoDto schemeOnPrtInfoDto : masterPointInfo) {

                        //按取餐点循环打印

                        //取餐点打印判断
                        List<Integer> receipts = new ArrayList<>();

                        for (EntityXfGoodListDishes entityXfGoodListDishes : mealSendReports) {
                            if (receipts.contains(entityXfGoodListDishes.getReceiptId())) {
                                continue;
                            }
                            receipts.add(entityXfGoodListDishes.getReceiptId());


                            String orderNo = RandomUtil.getRandomString(32);

                            StringBuilder content = new StringBuilder();
                            try {
                                content.append("<C><DB>取餐点汇总</DB></C><BR>");

                                if (request.getComId() == 693l) {
                                    content.append("<L>科室名称：");
                                } else {
                                    content.append("<L取餐点：");
                                }
                                content.append(getPointMealSendVo.getReceiptName());
                                content.append("</L><BR>");

                                content.append("<L>联系人：");
                                content.append(receiptMap.get(entityXfGoodListDishes.getReceiptId()).getRemark());
                                content.append("</L><BR>");

                                if (request.getComId() == 693l) {
                                    if (!CommonUtil.isNull(getPointMealSendVo.getReceiptName())) {
                                        content.append("<L>取餐点：");
                                        content.append(getPointMealSendVo.getReceiptName().contains("自取") ? "职工食堂自取" : "配送至取餐点");
                                        content.append("</L><BR>");
                                    }
                                }

                                content.append("<L>取餐时间：");
                                content.append(DateUtils.getStrDate(getPointMealSendVo.getMealDate(), "yyyy-MM-dd") + " " + stringMap.get(getPointMealSendVo.getMealNo()));
                                content.append("</L><BR>");


                                content.append("<L>菜品名称　　　　　　　　   数量");
                                content.append(PrintUtil4.getOrder2(integerList.get(entityXfGoodListDishes.getReceiptId()), 16, 6, 6, 4));
                                content.append("</L><BR>");


                                content.append("<L>打印时间：");
                                content.append(DateUtils.getTime());
                                content.append("</L><BR>");

//                            content.append("<QR>http://gzh.ocom30.com/</QR>");

//                            if(!flag){
//                                flag =true;
                                saveRecord(request.getComId(), orderNo, 3, content, schemeOnPrtInfoDto, 1);
//                            }


                            } catch (Exception e) {
                                e.printStackTrace();
                                log.info("组装订单内容失败！【{}】", e);
                                continue;
                            }
                            log.info("打印++++" + content.toString());

                        }
//
                    }
                }

                if (masterPointInfo != null && masterPointInfo1.size() > 0) {
                    for (GetSchemeOnPrtInfoDto schemeOnPrtInfoDto : masterPointInfo1) {

                        //按取餐点循环打印

                        //取餐点打印判断
                        List<Integer> receipts = new ArrayList<>();

                        for (EntityXfGoodListDishes entityXfGoodListDishes : mealSendReports) {
                            if (receipts.contains(entityXfGoodListDishes.getReceiptId())) {
                                continue;
                            }
                            if (request.getReceiptId() != null && !entityXfGoodListDishes.getReceiptId().equals(request.getReceiptId().intValue())) {
                                continue;
                            }

                            receipts.add(entityXfGoodListDishes.getReceiptId());


                            try {


                                List<Order> orderList = integerList.get(entityXfGoodListDishes.getReceiptId());

                                int size = 5;
                                int page2 = (int) Math.ceil((double) orderList.size() / size);


                                for (int page = page2; page > 0; page--) {


                                    String orderNo = RandomUtil.getRandomString(32);

                                    StringBuilder content = new StringBuilder();
//                                    content.append("<SIZE>40,30</SIZE>");

                                    Integer line = 1;

                                    Object paperSize = redisUtil.get("KitchenPrtInfoSize:"+schemeOnPrtInfoDto.getPrtSn());

                                    if(paperSize == null ){
                                        redisUtil.set("KitchenPrtInfoSize:"+schemeOnPrtInfoDto.getPrtSn(),1,86400l);
                                        content.append("<SIZE>"+schemeOnPrtInfoDto.getPaperSizeW()+","+ schemeOnPrtInfoDto.getPaperSizeH()+"</SIZE>");
                                    }

                                    content.append("<TEXT x=\"5\" y=\"2\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                                    content.append("科室名称：");
                                    content.append(getPointMealSendVo.getReceiptName());
                                    content.append("</TEXT>");

                                    content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                                    line++;
                                    content.append("联系人：");
                                    content.append(receiptMap.get(entityXfGoodListDishes.getReceiptId()).getRemark());
                                    content.append("</TEXT>");

                                    for (int i = 0; i < orderList.size(); i++) {
                                        if (i < (page - 1) * size || i >= (page) * size) {
                                            continue;
                                        }

                                        String title = orderList.get(i).getTitle();
                                        String num = orderList.get(i).getNum();
                                        content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                                        line++;
                                        content.append(title + "　　　 (" + num + ")");
                                        content.append("</TEXT>");
                                    }


//                                    if(page2!=1){
                                    content.append("<TEXT x=\"270\" y=\"190\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                                    line++;
                                    content.append(page + "/" + page2);
                                    content.append("</TEXT>");
//                                    }

                                    log.info("打印3++++" + content.toString());

                                    saveRecord(request.getComId(), orderNo, 3, content, schemeOnPrtInfoDto, 3);


                                }


                            } catch (Exception e) {
                                e.printStackTrace();
                                log.info("组装订单内容失败！【{}】", e);
                                continue;
                            }

                        }
//
                    }
                }

            }
        }


        return ResultUtil.success(map);
    }


    private StringBuilder getMasterPrintContent1(List<Order> orderList, PointConfigOnPointInfoDto pointInfoDto, EntityXfRecordProcess entityXfRecord, GetSchemeOnPrtInfoDto schemeOnPrtInfoDto) {
        StringBuilder content = new StringBuilder();
        try {
            /**
             * 1、 8×12 dot 英数字体
             * 2、 12×20 dot 英数字体
             * 3、 16×24 dot 英数字体
             * 4、 24×32 dot 英数字体
             * 5、 32×48 dot 英数字体
             * 6、 14×19 dot 英数字体 OCR-B
             * 7、 21×27 dot 英数字体 OCR-B
             * 8、 14×25 dot 英数字体 OCR-A
             * 9、 9×17 dot 英数字体
             * 10、 12×24 dot 英数字体
             * 11、 繁体中文 24×24Font(大五码)
             * 12、 简体中文 24×24Font(GB 码)
             * 13、 韩文 24×24Font(KS 码)
             */


            Object paperSize = redisUtil.get("KitchenPrtInfoSize:"+schemeOnPrtInfoDto.getPrtSn());

            if(paperSize == null ){
                redisUtil.set("KitchenPrtInfoSize:"+schemeOnPrtInfoDto.getPrtSn(),1,86400l);
                content.append("<SIZE>"+schemeOnPrtInfoDto.getPaperSizeW()+","+ schemeOnPrtInfoDto.getPaperSizeH()+"</SIZE>");
            }

//
//

            content.append("<TEXT x=\"5\" y=\"2\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
            content.append("科室名称：");
            content.append(entityXfRecord.getReceiptName());
            content.append("</TEXT>");

            Integer line = 1;

            if (!CommonUtil.isNull(entityXfRecord.getReceiptName())) {
                content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                line++;
                content.append("取餐点：");
                content.append(entityXfRecord.getReceiptName().contains("自取") ? "职工食堂自取" : "配送至取餐点");
                content.append("</TEXT>");
            }


            if (entityXfRecord.getPId() != null && entityXfRecord.getPId() > 0l) {
                content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                line++;
                content.append("联系人：");
                content.append(entityXfRecord.getPName() + "(" + entityXfRecord.getPCode() + ")");
                content.append("</TEXT>");
            }

            //菜品分类列表
            if (StringUtils.isNotBlank(schemeOnPrtInfoDto.getDishClass())) {
                String[] dishClassIds = schemeOnPrtInfoDto.getDishClass().split(",");
                List<String> list = Arrays.asList(dishClassIds);

                orderList = orderList.stream().filter(e -> list.contains(e.getDishesClassId())).collect(Collectors.toList());
            }

            //菜品列表
            if (StringUtils.isNotBlank(schemeOnPrtInfoDto.getDishes())) {
                String[] dishIds = schemeOnPrtInfoDto.getDishes().split(",");
                List<String> list = Arrays.asList(dishIds);

                orderList = orderList.stream().filter(e -> list.contains(e.getDishesId())).collect(Collectors.toList());
            }
//
//            content.append("名称　　　　　 单价  数量 金额<BR>");
//            content.append(PrintUtil4.getOrder(orderList, 14, 6, 3, 6));

            if (orderList.size() > 0) {
//                content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
//                line++;
//                content.append("名称　　单价    数量");
//                content.append("</TEXT>");

//                BigDecimal totals = new BigDecimal("0.0");
                for (int i = 0; i < orderList.size(); i++) {
                    String title = orderList.get(i).getTitle();
                    String price = orderList.get(i).getPrice();
                    String num = orderList.get(i).getNum();

//                    BigDecimal total = new BigDecimal(price).multiply(new BigDecimal(num));
//                    totals= totals.add(total);
                    content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                    line++;
                    content.append(title + "　　    　 (" + num + ")");
                    content.append("</TEXT>");
                }

//                content.append("<TEXT x=\"2\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
//                line++;
//                content.append("实收：");
//                content.append(totals + "元");
//                content.append("</TEXT>");
            }

//            content.append("<TEXT x=\"2\" y=\"" + line * 27 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
//            line++;
//            content.append("单号：");
//            content.append(entityXfRecord.getOrderNo());
//            content.append("</TEXT>");

            if (entityXfRecord.getComId() == 693l) {
//                try {
//                    content.append("<TEXT x=\"2\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
//                    line++;
//                    content.append("优惠金额：");
//                    content.append((double)entityXfRecord.getDiscount()/-100);
//                    content.append("</TEXT>");
//                }catch (Exception e){
//                    log.info("打印异常1 【{}】",e);
//                }
                try {
                    content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                    line++;
                    content.append("实际扣款金额：");
                    content.append((double) entityXfRecord.getRealMoney() / -100);
                    content.append("</TEXT>");
                } catch (Exception e) {
                    log.info("打印异常2【{}】", e);
                }
            }

            List<EntityXfMealInfo> mealInfos = mealInfoService.GetMealNameInfo(null, entityXfRecord.getComId(), null, null);

            //餐段
            Map<String, String> stringMap = mealInfos.stream().collect(Collectors.toMap(e -> e.getMealNo(),
                    e -> e.getMealName(),
                    (e1, e2) -> e1));
            line++;

            content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
            content.append("餐段：");
            content.append(new SimpleDateFormat("yyyy-MM-dd").format(entityXfRecord.getMealDate()) + "(" + stringMap.get(entityXfRecord.getMealNo()) + ")");
            content.append("</TEXT>");
            if (entityXfRecord.getComId() == 693l) {
                try {
                    line++;
                    content.append("<QR x=\"290\" y=\""+line*25+"\" e=\"L\" w=\"5\">");

                    content.append("order_no=");
                    content.append(entityXfRecord.getOrderNo());
                    content.append("</QR>");
                } catch (Exception e) {
                    log.info("打印异常2【{}】", e);
                }
            }

//
//            if(!CommonUtil.isNull(entityXfRecord.getReserved3())) {
//                content.append("<TEXT x=\"2\" y=\"" + line * 27 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
//                line++;
//                content.append("备注：");
//                content.append(entityXfRecord.getReserved3());
//                content.append("</TEXT>");
//            }

        } catch (Exception e) {
            e.printStackTrace();
            log.info("组装订单内容失败！【{}】", e);
        }
        return content;
    }

    /**
     * @param list
     * @param type    0定时的  1 即时打印
     * @param product 1 打印机  3标签机
     */
    private void handleListCount(List<KitchenPrtListDto> list, Integer type, Integer product) {

        if (product != 3) {
            return;
        }

        for (KitchenPrtListDto kitchenPrtListDto : list) {
            try {
                List<EntityXfMealTime> xfMealTimes = xfMealTimeService.getMealTimeList(kitchenPrtListDto.getComId());
                for (EntityXfMealTime entityXfMealTime : xfMealTimes) {

                    String esrTime = DateUtils.getDate() + " " + entityXfMealTime.getBeginTime();
                    Date start = DateUtils.getDate(esrTime, "yyyy-MM-dd HH:mm:ss");
                    long timestamp = start.getTime() - 3600000l * entityXfMealTime.getBeforeHour().longValue();

                    if (type == 0) {
                        long milliseconds = timestamp - System.currentTimeMillis();
                        long minutes = milliseconds / (60 * 1000);

                        //   System.out.println("Minutes difference: " + minutes);

                        //不需要打印的 不在时间内
                        if (minutes > 0 || minutes < -10l) {
                            continue;
                        }
                    }

                    GetPointMealSendReportsRequest request =new GetPointMealSendReportsRequest();
                    request.setComId(kitchenPrtListDto.getComId());
                    request.setStartTime(DateUtils.getDate());
                    request.setEndTime(DateUtils.getDate());
                    request.setMealNo(Integer.valueOf(entityXfMealTime.getMealNo()));

//                    request.setStartTime("2024-11-28");
//                    request.setEndTime("2024-11-28");

                    Result<List<GetPointMealSendVo>> pointMealSend = xfRecordFeign.getPointMealSend(request);

                    //空数据跳过
                    if (pointMealSend.getCode()!=200 || pointMealSend.getData()==null ||  pointMealSend.getData().size()==0) {
                        continue;
                    }

                    GetAdReceiptInfoRequest getAdReceiptInfoRequest = new GetAdReceiptInfoRequest();
                    getAdReceiptInfoRequest.setComId(request.getComId());
                    List<EntityReceiptAddress> adReceiptInfo = receiptAddressService.getAdReceiptInfo(request.getComId(), getAdReceiptInfoRequest);
                    Map<Integer, EntityReceiptAddress> receiptMap = adReceiptInfo.stream().collect(Collectors.toMap(EntityReceiptAddress::getReceiptId, EntityReceiptAddress -> EntityReceiptAddress));

//                    //餐段
//                    List<EntityXfMealInfo> mealInfos = mealInfoService.GetMealNameInfo(null, request.getComId(), null, null);
//                    Map<String, String> stringMap = mealInfos.stream().collect(Collectors.toMap(e -> e.getMealNo(),
//                            e -> e.getMealName(),
//                            (e1, e2) -> e1));

                    for (GetPointMealSendVo getPointMealSendVo:pointMealSend.getData()){

                        if (getPointMealSendVo.getDcTimes() == null || getPointMealSendVo.getDcTimes() == 0) {
                            continue;
                        }

                        StringBuilder content = new StringBuilder();

                        if (product == 3) {
//                            content.append("<SIZE>40,30</SIZE>");

                            Integer line = 1;

                            content.append("<TEXT x=\"5\" y=\"4\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                            content.append("科室名称:" + getPointMealSendVo.getReceiptName());
                            content.append("</TEXT>");


                            try {
                                content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                                line++;
                                content.append("联系人:" + receiptMap.get(getPointMealSendVo.getReceiptId()).getRemark());
                                content.append("</TEXT>");
                            }catch (Exception e){
                            }

                            content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                            line++;
                            content.append("套餐类型/数量:" + getPointMealSendVo.getDcTimes() + "份,水果" );
                            content.append("</TEXT>");

                            content.append("<TEXT x=\"5\" y=\"" + line * 45 + "\" font=\"12\" w=\"1\" h=\"2\" r=\"0\">");
                            line++;
                            content.append("打印时间:" + DateUtils.dateToStr(new Date()));
                            content.append("</TEXT>");
                        }
                        String orderNo = request.getStartTime() + "#" + request.getMealNo() + "#" + getPointMealSendVo.getReceiptId() ;

                        if (type == 0) {
                            //redis判断
                            if (!redisUtil.lock("KitchenPrinter:" + request.getComId() + "#" + orderNo, 60 * 60)) {
                                continue;
                            }
                        } else {
                            orderNo = request.getStartTime() + "#" + request.getMealNo() + "#" + getPointMealSendVo.getReceiptId() + "#" + RandomUtil.getRandomString(8);
                        }

                        GetSchemeOnPrtInfoDto schemeOnPrtInfoDto = JSON.parseObject(JSON.toJSONString(kitchenPrtListDto), GetSchemeOnPrtInfoDto.class);

                        saveRecord(entityXfMealTime.getComId(), orderNo, 4, content, schemeOnPrtInfoDto, product);

                        log.info("打印4++++" + content.toString());


                    }


                }
            }catch (Exception e){

            }


        }
    }

    public static void main(String[] args){
        EntityXfMealTime entityXfMealTime = new EntityXfMealTime();
        entityXfMealTime.setBeginTime("16:00:00");
        entityXfMealTime.setEndTime("21:00:00");
        entityXfMealTime.setBeforeHour(-2);
        entityXfMealTime.setAllowDays(1);
        entityXfMealTime.setAllowMinute(1230);

        try {
            //餐段时间
            long nowLong = new Date().getTime();

            String date =  DateUtils.getDate();


            //开始 beginDate  - allowday   + allowmin
            Date  after = DateUtil.getDate(date,"yyyy-MM-dd");
            after = DateUtil.getDateBefore(after,entityXfMealTime.getAllowDays());
            long begin  = after.getTime() +  (entityXfMealTime.getAllowMinute() * 60000);

            Date  endD  = DateUtil.getDate(date+ " " +entityXfMealTime.getBeginTime() ,"yyyy-MM-dd HH:mm:ss");
            long end  = endD.getTime() -  (entityXfMealTime.getBeforeHour() * 3600000);

            //截止 begintime - berforeHour


            log.info("时间区间:  【{}】【{}】" , begin , end);




            if (nowLong < begin  ||  nowLong> end ) {
//                return ResultUtil.error(ResultEnum.Err_4144);
                log.error("planKitchenPrinter====非当餐时间报错 dF5iP2fp 【{}】" ,"异常request");
                return;
//                return ResultUtil.error(ResultEnum.Err_4146);
            }

//            if(!(now.after(beginDate) && now.before(endDate))){
//                log.error("planKitchenPrinter====非当餐时间报错 dF5iP2fp 【{}】" ,request);
//                return ResultUtil.error(ResultEnum.Err_4146);
//            }

        } catch (ParseException e) {

        }
    }
}
